<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="code">
        <el-input
            v-model="queryParams.code"
            placeholder="请输入单据编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="源单编号" prop="sourceCode">
        <el-input
            v-model="queryParams.sourceCode"
            placeholder="请输入源单编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="buyPayReqList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
<!--      <el-table-column label="主键" align="center" prop="id"/>-->
      <el-table-column label="单据编号" align="center" prop="code" width="200"/>
      <el-table-column label="单据日期" align="center" prop="docTime" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="supName" width="150"/>
      <el-table-column label="客户" align="center" prop="cusName" width="150"/>
      <el-table-column label="单据阶段" align="center" prop="docStage">
        <template slot-scope="scope">
          <span v-if="scope.row.docStage == 0">编制完</span>
          <span v-if="scope.row.docStage == 1">执行中</span>
          <span v-if="scope.row.docStage == 2">执行完</span>
        </template>
      </el-table-column>
      <el-table-column label="审批结果" align="center" prop="approvalResult">
        <template slot-scope="scope">
          <span v-if="scope.row.approvalResult == 0 || scope.row.approvalResult == undefined || scope.row.approvalResult == null">待审核</span>
          <span v-else-if="scope.row.approvalResult == 1">审核通过</span>
          <span v-else-if="scope.row.approvalResult == 2">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column label="是否生效" align="center" prop="isEffect">
        <template slot-scope="scope">
          <span v-if="scope.row.isEffect == 0 || scope.row.isEffect == undefined || scope.row.isEffect == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>
      <el-table-column label="是否关闭" align="center" prop="isClose">
        <template slot-scope="scope">
          <span v-if="scope.row.isClose == 0 || scope.row.isClose == undefined || scope.row.isClose == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>
      <el-table-column label="是否作废" align="center" prop="isCancel">
        <template slot-scope="scope">
          <span v-if="scope.row.isCancel == 0 || scope.row.isCancel == undefined || scope.row.isCancel == null">否</span>
          <span v-else>是</span>
        </template>
      </el-table-column>

      <el-table-column label="申请金额" align="center" prop="requestAmount"/>
      <el-table-column label="已付金额" align="center" prop="paidAmount"/>

    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listBuyPayReq
} from "@/api/finance/buyPayReq";
import {listSupplies} from "@/api/basedata/supplies";

export default {
  name: "BuyPayReq",
  props:['supId','cusId'],
  data() {
    return {
      selectFksqList:[],
      //供应商数组
      supplierList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购付款申请表格数据
      buyPayReqList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        sourceCode: null,
        requestAmount: null,
        paidAmount: null,
        docTime: null,
        docStage: null,
        docMakeUserId: null,
        supId: this.supId,
        businessUserId: null,
        approvalResult: 1,
        approvalRemark: null,
        approvalUserId: null,
        isEffect: null,
        isClose: 0,
        isCancel: null,
        cusId:this.cusId
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [
          {required: true, message: "单据编号不能为空", trigger: "blur"}
        ],
        docTime: [
          {required: true, message: "单据日期不能为空", trigger: "blur"}
        ],
        // supId: [
        //   {required: true, message: "供应商不能为空", trigger: "blur"}
        // ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    returnSelectFksqList() {
      return this.selectFksqList;
    },
    setSupCusId(supId,cusId) {
      // alert(supId)

      this.queryParams.supId = supId;
      this.queryParams.cusId = cusId;
      this.getList();
    },
    // setCusId(cusId) {
    //   // alert(supId)
    //   this.queryParams.supId = null;
    //   this.queryParams.cusId = cusId;
    //   this.getList();
    // },
    // 新增初始化数据
    initBaseData() {
      //获取所有供应商
      listSupplies().then(res => {
        this.supplierList = res.rows
      })
      this.isFormMore = false;
      this.isApproval = false;
      this.cgrkDetailsList = [];
      this.cgrkList = [];
    },

    /** 查询采购付款申请列表 */
    getList() {
      this.loading = true;
      listBuyPayReq(this.queryParams).then(response => {
        this.buyPayReqList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: 'FKSQ-' + Date.now(),
        sourceCode: null,
        requestAmount: null,
        paidAmount: null,
        docTime: null,
        docStage: null,
        docMakeUserId: null,
        supId: this.supId,
        businessUserId: null,
        approvalResult: 1,
        approvalRemark: null,
        approvalUserId: null,
        isEffect: 1,
        isClose: null,
        isCancel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        list:[],
        cusId:this.cusId
      };
      this.resetForm("form");
      this.initBaseData();

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.selectFksqList = selection;
    },

  }
};
</script>
